package com.tanjie.blackbean.pojo.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
 * @author: tanjie
 * @date: 2022-03-30
 **/
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class BlackBeanResponse implements ResponseBean {

    private String message;

    private Integer code;

    private Object data;

    public BlackBeanResponse() {
    }

    public BlackBeanResponse(IResult result) {
        this.code = result.getCode();
        this.message = result.getMessage();
    }

    public BlackBeanResponse(IResult result, Object data) {
        this.code = result.getCode();
        this.message = result.getMessage();
        this.data = data;
    }

    @Override
    public ResponseBean create(IResult result, Object data) {
        this.setCode(result.getCode());
        this.setMessage(result.getMessage());
        this.setData(data);
        return this;
    }

    @Override
    public ResponseBean success() {
        this.setMessage(defaultSuccessMessage());
        this.setCode(defaultSuccessCode());
        return this;
    }

    @Override
    public ResponseBean success(Object data) {
        this.setMessage(defaultSuccessMessage());
        this.setCode(defaultSuccessCode());
        this.setData(data);
        return this;
    }

    @Override
    public ResponseBean success(Object data, String message) {
        this.setData(data);
        this.setMessage(message);
        this.setCode(defaultSuccessCode());
        return this;
    }

    @Override
    public ResponseBean successWithMessage(String message) {
        this.setMessage(message);
        this.setCode(defaultSuccessCode());
        return this;
    }

    @Override
    public ResponseBean failure() {
        this.setMessage(defaultFailureMessage());
        this.setCode(defaultSuccessCode());
        return this;
    }

    @Override
    public ResponseBean failure(Object data) {
        this.setData(data);
        this.setCode(defaultFailureCode());
        return this;
    }

    @Override
    public ResponseBean failure(Object data, String message) {
        this.data = data;
        this.code = defaultFailureCode();
        this.message = message;
        return this;
    }

    @Override
    public ResponseBean failureWithMessage(String message) {
        this.setMessage(message);
        this.setCode(defaultFailureCode());
        return this;
    }

}
